using UnityEngine;

public class BackgroundMusic : MonoBehaviour
{
	private static GameObject instance;

	public float defaultVolume = 1f;

	public float fadeValue = 0.1f;

	public bool active = true;

	public AudioSource audioSource;

	private void Awake()
	{
		defaultVolume = audioSource.volume;
		Object.DontDestroyOnLoad(base.gameObject);
		if (instance == null)
		{
			instance = base.gameObject;
		}
		else
		{
			Object.Destroy(base.gameObject);
		}
	}

	private void FixedUpdate()
	{
		if (active)
		{
			FadeIn();
		}
		else
		{
			FadeOut();
		}
	}

	public void FadeOut()
	{
		if (audioSource.volume > 0f)
		{
			audioSource.volume -= fadeValue * Time.deltaTime;
		}
	}

	public void FadeIn()
	{
		if (audioSource.volume < defaultVolume)
		{
			audioSource.volume += fadeValue * Time.deltaTime;
		}
	}
}
